# AWS Laravel docker

# AWS 設定

選擇EC2的主機

image-20200429201355685

下載Key Pair pem, 用放ssh登入

image-20200429201426680
# 要增加權限才能使用 參考 https://blog.csdn.net/u013197629/article/details/73608613
chmod 600 xxx.pem

image-20200429201448740

記下Public DNS (IPv4)

image-20200429201540331

開http port 80, 443

image-20200429222245870image-20200429222344359

使用ssh連接server

ssh -i xxx.pem [email protected]

image-20200429204700402

安裝git 和 docker

sudo yum update -y
sudo yum install git -y
sudo yum install docker -y

安裝 docker-compose (opens new window)

sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version

docker-compose version 1.25.5, build 8a1c60f6

如果想clone Private的頂目,需要增加ssh key

Clone GiltLab repository with SSH in AWS (opens new window)

ssh-keygen -t rsa -C "[email protected]" -b 4096
#copy
cat ~/.ssh/id_rsa.pub

image-20200429213317987

image-20200429213418828

Clone GitHub Private頂目

git clone [email protected]:xxxxxx.git

# Laravel 設定

我是使用submodule的方式使用Laradock (opens new window)

image-20200429214959666

上面的git clone 不會下載submodule,所以需要再下載: https://blog.chh.tw/posts/git-submodule/

git submodule init
git submodule update --recursive

接下來,根據官方教學設定一下, https://laradock.io/getting-started/#a-2-don-t-have-a-php-project-yet

cd laradock
cp env-example .env
vim .env

APP_CODE_PATH_HOST=../project-z/

先把ec2-user加入docker 群組:

[ Solution ] 啟動 docker-compose 發生 ERROR: Couldn’t connect to Docker daemon at http+docker://localunixsocket - is it running? 錯誤 (opens new window)

# 加入docker 群組
sudo gpasswd -a ${USER} docker
# 切換到su
sudo su
# 再切換到ec2-user, 藉此刷新
su ec2-user

啟動docker和docker-compose, 安裝需要一段時間

sudo systemctl start docker
docker-compose up -d nginx mysql


docker-compose exec workspace bash
# 安裝Laravel 依賴
composer install
cp .env.example .env
php artisan key:generate
# 參考
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:eCCidQPpxTux5Pcp3iYF56ZcV6DTXursA7Y6ZCYB9fw=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=flutter_plugin_collection_backend
DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

image-20200429223351479

# 其他操作

參考: http://notes.wingpage.net/content/Laravel/DockerSetup.html


# 相關問題:

# was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint

https://stackoverflow.com/a/33831697/5588637

參考:

image-20200430175133836image-20200430175325290

Last Updated: Thu Apr 30 2020 09:57:39 GMT+0000
贊助商連結
(adsbygoogle = window.adsbygoogle || []).push({});